/* Author: smayo@google.com

*/
var ZOO = window.ZOO || {};
ZOO.player;
ZOO.wbd;

//DEV
if (!window.console) console = {log: function() {}};
//LIVE
//console = {log: function() {}};

//inject the player API JS
var tag = document.createElement('script');
tag.src = "//www.youtube.com/iframe_api";
var firstScriptTag = document.getElementsByTagName('script')[0];
firstScriptTag.parentNode.insertBefore(tag, firstScriptTag);

$(document).ready(ready);

function ready(){
  //DATA is defined in timeData.js
  try{
    console.log('try WBD ready', ZOO.WorldBakingDay!=null);
    ZOO.wbd = new ZOO.WorldBakingDay(DATA).init();

    ZOO.wbd.setPlayer(ZOO.player);
  }
  catch(e){
    console.log("no setPlayer", e);
    setTimeout( ready, 100 );
  }
}


//trim beginning and trailing whitespace
function trim (str) {
    return str.replace(/^\s\s*/, '').replace(/\s\s*$/, '');
}



function onYouTubePlayerAPIReady() {
  ZOO.player = new ZOO.VideoPlayer('player', '3RFLdoJ2tRY');
  ZOO.player.init();
  try{
    ZOO.wbd.setPlayer(ZOO.player);
  }catch(e){
    console.log("no setPlayer", e);
  }
  

  var height = $('#player-holder').width() * (16/9);
  $('#player').attr({width: '100%', height: height});
}